package com.own.business.push.core.base.impl;

import com.own.business.push.core.base.BaseRepeatRegistrationIdMethod;
import com.own.business.push.core.base.BaseSaveRegistrationIdMethod;
import com.own.business.push.core.model.RegisterRegistrationIdModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

/**
 * DefaultRegistrationIdMethodImpl
 *
 * @author chenxueli
 * @date 2023-11-14 10:51:00
 */
@Slf4j
@Component
public class DefaultRegistrationIdMethodImpl {

    @Bean
    @ConditionalOnMissingBean(BaseSaveRegistrationIdMethod.class)
    private BaseSaveRegistrationIdMethod baseSaveRegistrationIdMethod() {
        return new BaseSaveRegistrationIdMethod() {
            @Override
            public void save(RegisterRegistrationIdModel model) {
                log.info("待实现BaseSaveRegistrationIdMethod");
            }

            @Override
            public void removeByUserId(Long userId) {
                log.info("待实现BaseSaveRegistrationIdMethod");
            }

            @Override
            public RegisterRegistrationIdModel getByUserId(Long userId) {
                log.info("待实现BaseSaveRegistrationIdMethod");
                return null;
            }

            @Override
            public List<RegisterRegistrationIdModel> listByUserIdList(Collection<Long> userIdList) {
                log.info("待实现BaseSaveRegistrationIdMethod");
                return null;
            }

            @Override
            public List<String> listRegIdListByModule(String module) {
                log.info("待实现BaseSaveRegistrationIdMethod");
                return null;
            }
        };
    }

    @Bean
    @ConditionalOnMissingBean(BaseRepeatRegistrationIdMethod.class)
    private BaseRepeatRegistrationIdMethod baseRepeatRegistrationIdMethod() {
        return (model, oldRegistrationId) -> {
            // 处理已经存在的逻辑
            log.info("{}:已经存在了，不需要再次注册", model.getUserId());
            return true;
        };
    }

}
